//% color="#00c4dd" iconWidth=50 iconHeight=40
namespace unihiker_WiFi{
    //% block="行空板连接Wi-Fi 名称[SSID] 密码[PSWD]" blockType="command" 
    ///% SSID.shadow="string"    SSID.defl="YourSSID"
    ///% PSWD.shadow="string"    PSWD.defl="YourPassword"
    export function unihiker_WiFi_init(parameter: any, block: any){
        let SSID = parameter.SSID.code;
        let PSWD = parameter.PSWD.code;
        Generator.addImport("from unihiker_connet_wifi import *");
        Generator.addDeclaration("unihiker_WiFi_init",`wifi_manager = WiFiManager()`)
        Generator.addDeclaration("unihiker_WiFi_init_connect",`response_success = wifi_manager.connect_wifi(${SSID}, ${PSWD})`)
        Generator.addCode(`response_success = wifi_manager.connect_wifi(${SSID}, ${PSWD})`)

    }
    

    //% block="Wi-Fi连接成功?" blockType="boolean"
    export function unihiker_WiFi_success(parameter: any, block: any){
        Generator.addDeclaration("unihiker_WiFi_init",`wifi_manager = WiFiManager()`)
        Generator.addCode(`wifi_manager.is_wifi_connected()`)
    }

    //% block="获取[INFO]" blockType="reporter"
    ///% INFO.shadow="dropdown"    INFO.options=INFO
    export function unihiker_get_WiFi_Status(parameter: any, block: any){
        let INFO = parameter.INFO.code;
        Generator.addImport("from unihiker_connet_wifi import *");
        Generator.addDeclaration("unihiker_WiFi_init",`wifi_manager = WiFiManager()`)
        Generator.addCode(`wifi_manager.get_wifi_${INFO}()`)
    }
    //% block="断开当前Wi-Fi连接" blockType="command"
    export function unihiker_WiFi_break(parameter: any, block: any){
        Generator.addImport("from unihiker_connet_wifi import *");
        Generator.addDeclaration("unihiker_WiFi_init",`wifi_manager = WiFiManager()`)
        Generator.addCode(`wifi_manager.break_wifi_connect()`)
    }
}